<template>
	<view class="content">
		<view class="head">
			<u-avatar :src="'/static/logo.png'" size="100" mode="circle" class="avatar" ></u-avatar>
			<view class="personInfo">
				<view v-if="hasLogin()&&userType=='sysPatientEntity'">
					<view>{{userInfo.patientName}}</view>
					<view class="account">帐号：{{userInfo.patientTel}}</view>
				</view>
				<view v-else-if="hasLogin()&&userType=='sysUserEntity'">
					<view>{{userInfo.username}}（{{userInfo.title}}）</view>
					<view class="account">帐号：{{userInfo.mobile}}</view>
				</view>
				<view class="goLogin" v-else @click="gotoLogin()">去登录</view>
			</view>
		</view>

		<u-cell-group>
			<u-cell-item icon="account-fill" title="个人信息" @click="profile"></u-cell-item>
			<!-- <u-cell-item icon="lock-fill" title="帐号&安全" @click="account"></u-cell-item> -->

			<u-cell-item icon="info-circle" title="关于我们" @click="about"></u-cell-item>

			<u-cell-item icon="info-circle" title="退出登录" @click="loginOut"></u-cell-item>
		</u-cell-group>

	</view>
</template>

<script>
	import {
		toast,
		clearStorageSync,
		setStorageSync,
		getStorageSync,
		useRouter
	} from '@/utils/utils.js'
	export default {
		data() {
			return {

				baseInfo: {
					name: '',
					phone: '',
					avatar: '',
					company_name: '',
					registerDate: '',
					login_code: '',
					auth: 0,
				},
				version: "",
			}
		},
		onLoad() {
			const that = this
			uni.getSystemInfo({
				success: function(res) {
					console.log("res", res)
					that.version = res.appVersion
				}
			})
		},
		async onShow() {
			//获取用户信息
			await this.getUserInfo();
			uni.$on('refresh', e => {
				uni.$off('refresh')
			})
		},

		// 下拉刷新
		onPullDownRefresh() {
			//console.log('refresh');
			uni.stopPullDownRefresh(); //停止刷新
		},


		methods: {
			gotoLogin() {
				useRouter('/pages/public/login', {}, 'navigateTo')
			},
			upload_avatar() {
				const _this = this
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: function(res) {

						uni.uploadFile({
							url: _this.$api_url + '/api/index/upload_cos',
							filePath: res.tempFilePaths[0],
							name: 'file',
							formData: {
								floder: 'avatar'
							},
							success: (uploadFileRes) => {
								//let retData = JSON.parse(uploadFileRes)

								let retData = JSON.parse(uploadFileRes.data)
								console.log('up:', retData)
								const _data = {
									avatar: retData.data.file
								}
								_this.$api.baseInfoSave(_data).then(ret => {
									if (ret.code == 1) {
										_this.baseInfo.avatar = retData.data.file
									} else {
										toast(res.msg)
									}
								})

							}
						});



					}
				});
			},
			service_center() {
				toast('未设置跳转，请自行定义')
			},

			profile() {
				//患者
				if (this.userType == 'sysPatientEntity') {
					useRouter('/pages/my/profile', {}, 'navigateTo')
				}
				//医护
				if (this.userType == 'sysUserEntity') {
					useRouter('/pages/my/profileYiHu', {}, 'navigateTo')
				}
			},
			account() {
				useRouter('/pages/my/account/index', {}, 'navigateTo')
			},
			setting() {
				useRouter('/pages/my/account/setting', {}, 'navigateTo')
			},
			about() {
				useRouter('/pages/my/about/index', {}, 'navigateTo')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {

		.head {
			background-color: rgb(71, 144, 255);
			display: flex;

			min-height: 200rpx;
			padding-top: 40rpx;

			.avatar {
				margin-left: 50rpx;
			}

			.personInfo {
				color: #fff;
				font-size: 30rpx;
				margin-left: 30rpx;
				line-height: 50rpx;

				.account {
					font-size: 26rpx;
				}

				.goLogin {
					font-size: 38rpx;
				}
			}

			.auth {
				flex: 1;
				text-align: right;
				margin-top: 40rpx;
			}

		}
	}
</style>
